package com.yadong.demo01;


import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class BeanPostProcessor1 implements BeanPostProcessor {
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("[" + beanName + "]" + "初始化 前处理方法");
		return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("[" + beanName + "]" + "初始化 后处理方法");
		return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
	}


	//调用BeanPostProcessor绝对不能替换原有bean, 只能对bean的属性进行修改注入之类的, 因为spring执行到此处循环依赖已经解决, bean的引用都已经赋值
//
//	@Override
//	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
//		if(beanName.equals("bean1")){
//			return new Bean1("更换后的bean1");
//		}
//		System.out.println("...");
//		return bean;
//	}

}
